function checkLogin()
{
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    if(document.formLogin.txtEmail.value=="")
        {
            alert("Please input Email");
            document.formLogin.txtEmail.focus();
            return false;
        }
    else
        {
            if(!emailFilter.test(document.formLogin.txtEmail.value))
                {
                    alert("Please enter a valid email address");
                    document.formLogin.txtEmail.focus();
                    return false;
                }
            else if(document.formLogin.txtEmail.value.match(illegalChars))
                {
                    alert("The email address contains illegal characters");
                    document.formLogin.txtEmail.focus();
                    return false;
                }
        }
    if(document.formLogin.txtPass.value=="")
        {
            alert("Please input Password");
            document.formLogin.txtPass.focus();
            return false;
        }
}

// nhap dau phay tu dong
function add_commas(number){
	//remove any existing commas...
	number=number.replace(/,/g, "");
	//start putting in new commas...
	number = '' + number;
	if (number.length > 3) {
		var mod = number.length % 3;
		var output = (mod > 0 ? (number.substring(0,mod)) : '');
		for (i=0 ; i < Math.floor(number.length / 3); i++) {
			if ((mod == 0) && (i == 0))
				output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
			else
				output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
		}
		return (output);
	}
	else return number;
}

// chuyen dinh dang date
 function loadCalendar(id){ 	
		new JsDatePick({
				useMode:2,
				target: id,
				dateFormat:"%Y-%m-%d",
				cellColorScheme :"aqua"			
		});
	}
		
		

function calc3(begin,end){
	OT=0;ON=0;WT=0;
	if (begin==0 && end==0) return;
	if (begin<12) begin=12;
	x=end -begin;
	if (x>=5) x=x-1;
	if (x>8){
		WT=8;
		OT=x-8;
	}else{
		WT=x;
	}
	return;
}
function calc1(begin,end){
	OT=0;ON=0;WT=0;
	if (begin==0 && end==0) return;
	if (begin<23 && begin >0) begin=23;
	if (end <begin) end=end +24;
	x=end -begin;
	if (x>=5) x=x-1;
	if  (x>8) {
		WT=8;
		OT=x-8;
	}else{
		WT=x;
	} 
	return;
	
}
function calc(begin,end)
{  
	
	OT=0;ON=0;WT=0;
	if (begin==0 && end==0) return;
	if (begin < 8 && begin>7) begin =8;
	if (end>24) end=24;
	if (begin >end) {end= 24+end;}	
	x=end -begin;	
	if (end >21 ){
		if (begin >=21) {ON=x; return;}
		OT=calc(begin,21);
		ON=end -21;
		return;						
	}
	if (end>18 && end<=21){
		if (begin >=18) {OT=x;return OT;}
		WT=calc(begin,18);
		OT=end -18;		
		return OT;
	}
	if (end<=18){
		if (x< 4) {WT=x; return WT; }
		if (x>=4 && x<5) {WT=4;return WT;}
		if (x>=5 && x<9) {WT=x-1;return WT;}
		WT=8;return WT; 
	}	
	
}

function getHours(dt){
	if ( dt.search(':')==-1) return parseFloat(dt);
	else{
		var	da=dt.split(':');
		x=parseFloat(da[0]);
		x=x + parseFloat(da[1])/60;
		return x; 
	}	 
	
}
function OnchangeTime(dropdown,row){
	
	 var myindex  = dropdown.selectedIndex;	
    var SelValue = dropdown.options[myindex].value;
    var form=document.workDay;
    if (SelValue=='Night') { 
		    $( '#a'+row).val('23:00');
		    $('#b'+row).val('08:00');
    }
    if (SelValue=='Normal'){
    		$( '#a'+row).val('08:00');
		    $('#b'+row).val('17:00');
    }
    if (SelValue=='Moon'){
    		$( '#a'+row).val('12:00');
		    $('#b'+row).val('21:00');
    }
    if (SelValue=='SL'|| SelValue=='UL'||SelValue=='PL'||SelValue=='AL') 
     {
     		$( '#a'+row).val('00:00');
		    $('#b'+row).val('00:00');
     }
    calculate(row);

}

function calculate(i){		
		var form= document.workDay;
		var begin =getHours($('#a'+i).val());	var end =getHours($('#b'+i).val());
			if ($('#f'+i).val()=='Night') {calc1(begin,end);}
			else if ($('#f'+i).val()=='Moon'){
				calc3(begin,end);
			}else{
				calc(begin,end);
				}
		$('#c'+i).val(WT);$('#d'+i).val(OT);$('#e'+i).val(ON);
			
}

function autocalculate(){
		var i=0;
		while(i<7){
			calculate(i);
			i++;
		}
	
}


function dtval(d,e) {
		var pK = e ? e.which : window.event.keyCode;
		if (pK == 8) {d.value = substr(0,d.value.length-1); return;}
		var dt = d.value;
		var da = dt.split('-');
		for (var a = 0; a < da.length; a++) {if (da[a] != +da[a]) da[a] = da[a].substr(0,da[a].length-1);}
		//if (da[2] > 31) da[1] = da[2].substr(0,da[2].length-1);
		if (da[1] > 12) {da[2] = da[1].substr(da[1].length-1,1);da[1] = '0'+da[1].substr(0,da[1].length-1);}
		if (da[2] > 31) {da[2] =  da[2].substr(0,da[2].length-1)};//da[2].substr(da[2].length-1,1);da[2] = '0'+da[2].substr(0,da[2].length-1);}
		dt = da.join('-');
		if (dt.length == 4 || dt.length == 7) dt += '-';
		d.value = dt;
}
function checkFormInsertStaff()
{
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    var stripped1 = document.formInsertStaff.txtHomePhone.value.replace(/[\(\)\.\-\ ]/g, '');
    var stripped2 = document.formInsertStaff.txtCellPhone.value.replace(/[\(\)\.\-\ ]/g, '');
    var stripped3 = document.formInsertStaff.txtIDNumber.value.replace(/[\(\)\.\-\ ]/g, '');
    var stripped4 = document.formInsertStaff.txtStaffID.value.replace(/[\(\)\.\-\ ]/g, '');
    if(document.formInsertStaff.txtStaffID.value=="")
        {
            alert("Please input Staff ID");
            document.formInsertStaff.txtStaffID.focus();
            return false;
        }
        else
        {
            if(isNaN(parseInt(stripped4)))
                {
                    alert("The Staff ID contains illegal characters");
                    document.formInsertStaff.txtStaffID.focus();
                    return false;
                }
            else if(stripped4.length!=11)
                {
                    alert("The Staff ID is the wrong length");
                    document.formInsertStaff.txtStaffID.focus();
                    return false;
                }
        }
    if(document.formInsertStaff.txtFullName.value=="")
        {
           alert("Please input Full Name");
           document.formInsertStaff.txtFullName.focus();
           return false;
        }
    if(document.formInsertStaff.txtFirstName.value=="")
        {
           alert("Please input First Name");
           document.formInsertStaff.txtFirstName.focus();
           return false;
        }
    if(document.formInsertStaff.txtLastName.value=="")
        {
           alert("Please input Last Name");
           document.formInsertStaff.txtLastName.focus();
           return false;
        }
if(document.formInsertStaff.txtPlaceBirthday.value=="")
        {
           alert("Please input Place of Birthday");
           document.formInsertStaff.txtPlaceBirthday.focus();
           return false;
        }
    if(document.formInsertStaff.txtMaritalStatus.value=="")
        {
           alert("Please input Marital Status");
           document.formInsertStaff.txtMaritalStatus.focus();
           return false;
        }
    /*if(document.formInsertStaff.txtPersonalTaxCode.value=="")
        {
           alert("Please input Personal Tax Code");
           document.formInsertStaff.txtPersonalTaxCode.focus();
           return false;
        }*/
    if(document.formInsertStaff.txtIDNumber.value=="")
        {
           alert("Please input ID Number");
           document.formInsertStaff.txtIDNumber.focus();
           return false;
        }
    else
        {
            if(isNaN(parseInt(stripped3)))
                {
                    alert("The ID Number contains illegal characters");
                    document.formInsertStaff.txtIDNumber.focus();
                    return false;
                }
        }
    if(document.formInsertStaff.txtPlaceOfIssue.value=="")
        {
           alert("Please input Place of Issue");
           document.formInsertStaff.txtPlaceOfIssue.focus();
           return false;
        }
    /*if(document.formInsertStaff.txtHomePhone.value=="")
        {
           alert("Please input Home Phone");
           document.formInsertStaff.txtHomePhone.focus();
           return false;
        }
    /*else
        {
            if(isNaN(parseInt(stripped1)))
                {
                    alert("The phone number contains illegal characters");
                    document.formInsertStaff.txtHomePhone.focus();
                    return false;
                }
            else if(stripped1.length>11||stripped1<9)
                {
                    alert("The phone number is the wrong length");
                    document.formInsertStaff.txtHomePhone.focus();
                    return false;
                }
        }
     if(document.formInsertStaff.txtCellPhone.value=="")
        {
           alert("Please input Cell Phone");
           document.formInsertStaff.txtCellPhone.focus();
           return false;
        }
    else
        {
            if(isNaN(parseInt(stripped2)))
                {
                    alert("The phone number contains illegal characters");
                    document.formInsertStaff.txtCellPhone.focus();
                    return false;
                }
            else if(stripped2.length>11||stripped2<9)
                {
                    alert("The phone number is the wrong length");
                    document.formInsertStaff.txtCellPhone.focus();
                    return false;
                }
        }
   if(document.formInsertStaff.txtPersonalEmail1.value=="")
        {
            alert("Please input Email");
            document.formInsertStaff.txtPersonalEmail1.focus();
            return false;
        }
    else
        {
            if(!emailFilter.test(document.formInsertStaff.txtPersonalEmail1.value))
                {
                    alert("Please enter a valid email address");
                    document.formInsertStaff.txtPersonalEmail1.focus();
                    return false;
                }
            else if(document.formInsertStaff.txtPersonalEmail1.value.match(illegalChars))
                {
                    alert("The email address contains illegal characters");
                    document.formInsertStaff.txtPersonalEmail1.focus();
                    return false;
                }
        }
        if(document.formInsertStaff.txtPersonalEmail2.value=="")
        {
            alert("Please input Email");
            document.formInsertStaff.txtPersonalEmail2.focus();
            return false;
        }
    else
        {
            if(!emailFilter.test(document.formInsertStaff.txtPersonalEmail2.value))
                {
                    alert("Please enter a valid email address");
                    document.formInsertStaff.txtPersonalEmail2.focus();
                    return false;
                }
            else if(document.formInsertStaff.txtPersonalEmail2.value.match(illegalChars))
                {
                    alert("The email address contains illegal characters");
                    document.formInsertStaff.txtPersonalEmail2.focus();
                    return false;
                }
        }
    if(document.formInsertStaff.txtCompanyEmail.value=="")
        {
            alert("Please input Email");
            document.formInsertStaff.txtCompanyEmail.focus();
            return false;
        }
    else
        {
            if(!emailFilter.test(document.formInsertStaff.txtCompanyEmail.value))
                {
                    alert("Please enter a valid email address");
                    document.formInsertStaff.txtCompanyEmail.focus();
                    return false;
                }
            else if(document.formInsertStaff.txtCompanyEmail.value.match(illegalChars))
                {
                    alert("The email address contains illegal characters");
                    document.formInsertStaff.txtCompanyEmail.focus();
                    return false;
                }
        }*/
     
}
function checkNext()
{
    /*if(document.formInsertStaff.txtPANSWD.value=="")
        {
            alert("Please input PA Address");
            document.formInsertStaff.txtPANSWD.focus();
            return false;
        }
       if(document.formInsertStaff.txtPACity.value=="")
        {
            alert("Please input PA City");
            document.formInsertStaff.txtPACity.focus();
            return false;
        }
         if(document.formInsertStaff.txtPACountry.value=="")
        {
            alert("Please input PA Country");
            document.formInsertStaff.txtPACountry.focus();
            return false;
        }
        if(document.formInsertStaff.txtCVSUmup.value=="")
        {
            alert("Please input CV Sumup");
            document.formInsertStaff.txtCVSUmup.focus();
            return false;
        }
       if(document.formInsertStaff.txtCANSWD.value=="")
        {
            alert("Please input PA Address");
            document.formInsertStaff.txtCANSWD.focus();
            return false;
        }
       if(document.formInsertStaff.txtCACity.value=="")
        {
            alert("Please input CA City");
            document.formInsertStaff.txtCACity.focus();
            return false;
        }
        if(document.formInsertStaff.txtCACountry.value=="")
        {
            alert("Please input CA Country");
            document.formInsertStaff.txtCACountry.focus();
            return false;
        }*/     
}
function checkFormInsertCV()
{
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    var stripped1 = document.formInsertCV.txtHomePhone.value.replace(/[\(\)\.\-\ ]/g, '');
    var stripped2 = document.formInsertCV.txtCellPhone.value.replace(/[\(\)\.\-\ ]/g, '');
    var stripped3 = document.formInsertCV.txtIDNumber.value.replace(/[\(\)\.\-\ ]/g, '');
    if(document.formInsertCV.txtFullName.value=="")
        {
           alert("Please input Full Name");
           document.formInsertCV.txtFullName.focus();
           return false;
        }
    if(document.formInsertCV.txtFirstName.value=="")
        {
           alert("Please input First Name");
           document.formInsertCV.txtFirstName.focus();
           return false;
        }
    if(document.formInsertCV.txtLastName.value=="")
        {
           alert("Please input Last Name");
           document.formInsertCV.txtLastName.focus();
           return false;
        }
    if(document.formInsertCV.txtPlaceBirthday.value=="")
        {
            alert("Please input Place of Birthday");
            document.formInsertCV.txtPlaceBirthday.focus();
            return false;
        }
    if(document.formInsertCV.txtMaritalStatus.value=="")
        {
            alert("Please input Maristal Status");
            document.formInsertCV.txtMaritalStatus.focus();
            return false;
        }
    if(document.formInsertCV.txtIDNumber.value=="")
        {
           alert("Please input ID Number");
           document.formInsertCV.txtIDNumber.focus();
           return false;
        }
    else
        {
            if(isNaN(parseInt(stripped3)))
                {
                    alert("The ID Number contains illegal characters");
                    document.formInsertCV.txtIDNumber.focus();
                    return false;
                }
        }
        
    if(document.formInsertCV.txtPOI.value=="")
        {
            alert("Please input Place of Issue");
            document.formInsertCV.txtPOI.focus();
            return false;
        }
    /*    if(document.formInsertCV.txtPersonalEmail1.value=="")
        {
            alert("Please input Email");
            document.formInsertCV.txtPersonalEmail1.focus();
            return false;
        }
    else
        {
            if(!emailFilter.test(document.formInsertCV.txtPersonalEmail1.value))
                {
                    alert("Please enter a valid email address");
                    document.formInsertCV.txtPersonalEmail1.focus();
                    return false;
                }
            else if(document.formInsertCV.txtPersonalEmail1.value.match(illegalChars))
                {
                    alert("The email address contains illegal characters");
                    document.formInsertCV.txtPersonalEmail1.focus();
                    return false;
                }
        }
       if(document.formInsertCV.txtPersonalEmail2.value=="")
        {
            alert("Please input Email");
            document.formInsertCV.txtPersonalEmail2.focus();
            return false;
        }
    else
        {
            if(!emailFilter.test(document.formInsertCV.txtPersonalEmail2.value))
                {
                    alert("Please enter a valid email address");
                    document.formInsertCV.txtPersonalEmail2.focus();
                    return false;
                }
            else if(document.formInsertCV.txtPersonalEmail2.value.match(illegalChars))
                {
                    alert("The email address contains illegal characters");
                    document.formInsertCV.txtPersonalEmail2.focus();
                    return false;
                }
        } 
    if(document.formInsertCV.txtHomePhone.value=="")
        {
           alert("Please input Home Phone");
           document.formInsertCV.txtHomePhone.focus();
           return false;
        }
    else
        {
            if(isNaN(parseInt(stripped1)))
                {
                    alert("The phone number contains illegal characters");
                    document.formInsertCV.txtHomePhone.focus();
                    return false;
                }
            else if(stripped1.length>11||stripped1<9)
                {
                    alert("The phone number is the wrong length");
                    document.formInsertCV.txtHomePhone.focus();
                    return false;
                }
        }
     if(document.formInsertCV.txtCellPhone.value=="")
        {
           alert("Please input Cell Phone");
           document.formInsertCV.txtCellPhone.focus();
           return false;
        }
    /*else
        {
            if(isNaN(parseInt(stripped2)))
                {
                    alert("The phone number contains illegal characters");
                    document.formInsertCV.txtCellPhone.focus();
                    return false;
                }
            else if(stripped2.length>11||stripped2<9)
                {
                    alert("The cell number is the wrong length");
                    document.formInsertCV.txtCellPhone.focus();
                    return false;
                }
        }
     if(document.formInsertCV.txtCVSUmup.value=="")
        {
            alert("Please input CV Sumup");
            document.formInsertCV.txtCVSUmup.focus();
            return false;
        }*/
     if(document.formInsertCV.txtPositionInterview.value=="")
        {
            alert("Please input Position Interview");
            document.formInsertCV.txtPositionInterview.focus();
            return false;
        }
}
function checkRole(){
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    if(document.role.email.value=="")
        {
            alert("Please input Email");
            document.role.email.focus();
            return false;
        }
    else
        {
            if(!emailFilter.test(document.role.email.value))
                {
                    alert("Please enter a valid email address");
                    document.role.email.focus();
                    return false;
                }
            else if(document.role.email.value.match(illegalChars))
                {
                    alert("The email address contains illegal characters");
                    document.role.email.focus();
                    return false;
                }
        }
    if(document.role.password.value=="")
        {
           alert("Please input password");
           document.role.password.focus();
           return false;
        }
    if(document.role.FullName.value=="")
        {
           alert("Please input FullName");
           document.role.FullName.focus();
           return false;
        }  
	        
        
}
function checkLab(){
	 
    if(document.lab.LabName.value=="")
        {
           alert("Please input LabName");
           document.lab.LabName.focus();
           return false;
        } 
	if(document.lab.Customer.value=="")
        {
           alert("Please input Customer");
           document.lab.Customer.focus();
           return false;
        }
	if(document.lab.Country.value=="")
        {
           alert("Please input LabName");
           document.lab.Country.focus();
           return false;
        }                 
    return true;     
}



// check monthlyAllowStaff
function checkMAS(){
	 if(document.MAS.ActiveDate.value=="")
        {
           alert("Please input ActiveDate");
           document.MAS.ActiveDate.focus();
           return false;
        }else{
       		return check_Date(document.MAS.ActiveDate.value);
        }
    return true;     
}

function checkLabStaff(){
	if(document.labStaff.Worklevel.value=="")
        {
           alert("Please input Worklevel");
           document.labStaff.Worklevel.focus();
           return false;
        }
    if(document.labStaff.BasicSalary.value=="")
        {
           alert("Please input BasicSalary");
           document.labStaff.BasicSalary.focus();
           return false;
        }
              
        
}

function checkCustomer(){
	if(document.customer.Customer_ID.value=="")
        {
           alert("Please input Customer_ID");
           document.customer.Customer_ID.focus();
           return false;
        }
    if (isNaN(document.customer.Customer_ID.value))
    {
    	alert("Please input Lab_ID is numeric");
        document.customer.Customer_ID.focus();
        return false;
    } 
    if(document.customer.CustomerName.value=="")
        {
           alert("Please input CustomerName");
           document.customer.CustomerName.focus();
           return false;
        }  
    if(document.customer.Country.value=="")
        {
           alert("Please input Contry");
           document.customer.Country.focus();
           return false;
        }  
    return true;     
}
function checkDepartment(){
	if(document.department.Department_ID.value=="")
        {
           alert("Please input Department_ID");
           document.department.Department_ID.focus();
           return false;
        }
    if(document.department.Department.value=="")
        {
           alert("Please input DepartmentName");
           document.department.Department.focus();
           return false;
        }  
    return true;     
}
function checkProject()
{	 
    if(document.project.ProjectName.value=="")
        {
           alert("Please input ProjectName");
           document.project.ProjectName.focus();
           return false;
        }  
    if(document.project.BeginDate.value=="")
        {
           alert("Please input BeginDate");
           document.project.BeginDate.focus();
           return false;
        }else{
       		if (check_Date(document.project.BeginDate.value) == false)
       		return false;
        }
        
   if(document.project.EndDate.value=="")
        {
           alert("Please input EndDate");
           document.project.EndDate.focus();
           return false;
        }else{
       	 return	check_Date(document.project.EndDate.value);
        }  
    
    return true;     
}
/// check annex
function checkAnnex(){
	if(document.annex.Annex_ID.value=="")
        {
           alert("Please input Annex_ID");
           document.annex.Annex_ID.focus();
           return false;
        }
    if (isNaN(document.annex.Annex_ID.value))
    {
    	alert("Please input Annex_ID is numeric");
        document.annex.Annex_ID.focus();
        return false;
    } 
    if(document.annex.Salary.value=="")
        {
           alert("Please input Salary");
           document.annex.Salary.focus();
           return false;
        }  
    if(document.annex.AnnexDate.value=="")
        {
           alert("Please input AnnexDate");
           document.annex.AnnexDate.focus();
           return false;
        }else{
       		return check_Date(document.annex.AnnexDate.value);
        }     
   return true;     
}

//check mini salary
function checkMiniSalary(){	
    if(document.miniSalary.Salary.value=="")
        {
           alert("Please input Salary");
           document.miniSalary.Salary.focus();
           return false;
        }  
    if(document.miniSalary.EffectiveDate.value=="")
        {
           alert("Please input EffectiveDate");
           document.miniSalary.EffectiveDate.focus();
           return false;
        }else{
       		return check_Date(document.miniSalary.EffectiveDate.value);
        }     
   return true;     
}

//check PIT
function checkPIT(){
	
    if(document.PIT.IndividualDeduction.value=="")
        {
           alert("Please input IndividualDeduction");
           document.PIT.IndividualDeduction.focus();
           return false;
        }  
    if(document.PIT.Dependent.value=="")
        {
           alert("Please input Dependent");
           document.PIT.Dependent.focus();
           return false;
        }    
    if(document.PIT.EffectiveDate.value=="")
        {
           alert("Please input EffectiveDate");
           document.PIT.EffectiveDate.focus();
           return false;
        }else{
       		return check_Date(document.PIT.EffectiveDate.value);
        }     
   return true;     
}

//check tax
function checkTax(){	
    if(document.tax.From.value=="")
        {
           alert("Please input From");
           document.tax.From.focus();
           return false;
        }      
     if(document.tax.Percent.value=="")
        {
           alert("Please input Percent");
           document.tax.Percent.focus();
           return false;
        }   
    if(document.tax.EffectiveDate.value=="")
        {
           alert("Please input EffectiveDate");
           document.tax.EffectiveDate.focus();
           return false;
        }else{
       		return check_Date(document.tax.EffectiveDate.value);
        }     
   return true;     
}

//check SHU
function checkSHU(){
	
    if(document.SHU.E_SI.value=="")
        {
           alert("Please input E_SI");
           document.SHU.E_SI.focus();
           return false;
        }  
     if(document.SHU.E_HI.value=="")
        {
           alert("Please input E_HI");
           document.SHU.E_HI.focus();
           return false;
        }  
	 if(document.SHU.E_UI.value=="")
        {
           alert("Please input E_UI");
           document.SHU.E_UI.focus();
           return false;
        } 
	 if(document.SHU.C_SI.value=="")
        {
           alert("Please input C_SI");
           document.SHU.C_SI.focus();
           return false;
        }  
     if(document.SHU.C_HI.value=="")
        {
           alert("Please input C_HI");
           document.SHU.C_HI.focus();
           return false;
        }  
	 if(document.SHU.C_UI.value=="")
        {
           alert("Please input C_UI");
           document.SHU.C_UI.focus();
           return false;
        }                     
      
   
    if(document.SHU.EffectiveDate.value=="")
        {
           alert("Please input EffectiveDate");
           document.SHU.EffectiveDate.focus();
           return false;
        }else{
       		return check_Date(document.SHU.EffectiveDate.value);
        }     
   return true;     
}
//check overtime
function checkOverTime(){
	
    if(document.overTime.OT_Weekday.value=="")
        {
           alert("Please input OT_Weekday");
           document.overTime.OT_Weekday.focus();
           return false;
        }
     if(document.overTime.OT_Weekend.value=="")
        {
           alert("Please input OT_Weekend");
           document.overTime.OT_Weekend.focus();
           return false;
        }
     if(document.overTime.OT_Holiday.value=="")
        {
           alert("Please input OT_Holiday");
           document.overTime.OT_Holiday.focus();
           return false;
        }
     if(document.overTime.ON_Weekday.value=="")
        {
           alert("Please input ON_Weekday");
           document.overTime.ON_Weekday.focus();
           return false;
        }
      if(document.overTime.ON_Weekend.value=="")
        {
           alert("Please input ON_Weekend");
           document.overTime.ON_Weekend.focus();
           return false;
        }
      if(document.overTime.ON_Holiday.value=="")
        {
           alert("Please input ON_Holiday");
           document.overTime.ON_Holiday.focus();
           return false;
        }               
    
   
    if(document.overTime.EffectiveDate.value=="")
        {
           alert("Please input EffectiveDate");
           document.overTime.EffectiveDate.focus();
           return false;
        }else{
       		return check_Date(document.overTime.EffectiveDate.value);
        }     
   return true;     
}


//check SIHI
function checkSIHI(){
	if(document.SIHI.SIHI_ID.value=="")
        {
           alert("Please input SIHI_ID");
           document.SIHI.SIHI_ID.focus();
           return false;
        }
    if (isNaN(document.SIHI.SIHI_ID.value))
    {
    	alert("Please input SIHI_ID is numeric");
        document.SIHI.SIHI_ID.focus();
        return false;
    } 
    if(document.SIHI.SI_Book_No.value=="")
        {
           alert("Please input SI_Book_No");
           document.SIHI.SI_Book_No.focus();
           return false;
        }  
    if(document.SIHI.IssuedDate1.value=="")
        {
           alert("Please input IssuedDate1");
           document.SIHI.IssuedDate1.focus();
           return false;
        }else{
       		check_Date(document.SIHI.IssuedDate1.value);
        } 
	if(document.SIHI.HI_Card_No.value=="")
        {
           alert("Please input HI_Card_No");
           document.SIHI.HI_Card_No.focus();
           return false;
        }
     if(document.SIHI.IssuedDate2.value=="")
        {
           alert("Please input IssuedDate2");
           document.SIHI.IssuedDate2.focus();
           return false;
        }else{
       		check_Date(document.SIHI.IssuedDate2.value);
        }  
     if(document.SIHI.ExpiredDate.value=="")
        {
           alert("Please input ExpiredDate");
           document.SIHI.ExpiredDate.focus();
           return false;
        }else{
       		return check_Date(document.SIHI.ExpiredDate.value);
        }    
                      
   return true;     
}

// check monthlyAllow
function checkMonthlyAllow(){
	
    if(document.monthlyAllow.Allowance.value=="")
        {
           alert("Please input Allowance");
           document.monthlyAllow.Allowance.focus();
           return false;
        }    
    if(document.monthlyAllow.Amount.value=="")
        {
           alert("Please input Amount");
           document.monthlyAllow.Amount.focus();
           return false;
        }
  
      
    if(document.monthlyAllow.ExcutiveDate.value=="")
        {
           alert("Please input ExcutiveDate");
           document.monthlyAllow.ExcutiveDate.focus();
           return false;
        }else{
       		return check_Date(document.monthlyAllow.ExcutiveDate.value);
        }     
   return true;     
}

// check customer report
function checkCustomerReport(){
	if(document.customerReport.FromDate.value=="")
        {
           alert("Please input FromDate");
           document.customerReport.FromDate.focus();
           return false;
        }else{
       		if (check_Date(document.customerReport.FromDate.value)== false)
       		return false ;
        }
    if(document.customerReport.ToDate.value=="")
        {
           alert("Please input ToDate");
           document.customerReport.ToDate.focus();
           return false;
        }else{
       		if (check_Date(document.customerReport.ToDate.value)==false)
       		return false;
        }    	
    
     if(document.getElementById('overtime').checked)
		        {
		           if (document.customerReport.OverTime.value==""){
		           		alert("please input overtime");
		           		document.customerReport.OverTime.focus();
		           		return false;
		           }
		        }else
		 if (document.getElementById('percent').checked)
		   {
		   		if (document.customerReport.Percent.value==""){
		   			alert("please input Percent");
		   			document.customerReport.Percent.focus();
		   			return false;
		   		}			
		   }else{
		   	
			alert ("please input salary type");
				return false;				   	
		   	
		   }    
    
  
      
         
   return true;     
}



// check section
function checkSection(){
	if(document.section.Session_ID.value=="")
        {
           alert("Please input Section_ID");
           document.section.Session_ID.focus();
           return false;
        }
    if(document.section.SessionName.value=="")
        {
           alert("Please input SectionName");
           document.section.SessionName.focus();
           return false;
        }  
    return true;     
}

function checkContractType(){
	if(document.contractType.ContractType_ID.value=="")
        {
           alert("Please input ContractType_ID");
           document.contractType.ContractType_ID.focus();
           return false;
        }
    if(document.contractType.ContractTypeName.value=="")
        {
           alert("Please input ContractTypeName");
           document.contractType.ContractTypeName.focus();
           return false;
        }  
    return true;    
}

//check contract

function checkContract(){
	if(document.contract.Contract_ID.value=="")
        {
           alert("Please input Contract_ID");
           document.contract.Contract_ID.focus();
           return false;
        }
    if (isNaN(document.contract.Contract_ID.value))
    {
    	alert("Please input Contract_ID is numeric");
        document.contract.Contract_ID.focus();
        return false;
    } 
  
    if(document.contract.JoiningDate.value=="")
        {
           alert("Please input JoiningDateDate");
           document.contract.JoiningDate.focus();
           return false;
        }else{
       		return check_Date(document.contract.JoiningDate.value);
        }
        
   if(document.contract.EffectiveDate.value!="")
        {
            return check_Date(document.contract.EffectiveDate.value);
        }  
   if(document.contract.ExpiredDate.value!="")
        {
            return check_Date(document.contract.ExpiredDate.value);
        }  
	if(document.contract.ExitDate.value!="")
        {
           return check_Date(document.contract.ExitDate.value);
        }  
	if(document.contract.EffectiveDate.value!="")
        {
            return check_Date(document.contract.ResignationDate.value);
        }                  
    
    return true;     
}




function checkFormInsertInterview()
{
    /*if(document.formInsertInterview.txtCVUsername.value=="")
        {
          alert("Please input CV UserName");
          document.formInsertInterview.txtCVUsername.focus();
          return false;
        }*/
    if(document.formInsertInterview.txtInterviewer.value=="")
        {
          alert("Please input Interviewer");
          document.formInsertInterview.txtInterviewer.focus();
          return false;
        }
}

function check_Date(datefield)
{
   // Regular expression used to check if date is in correct format
   var pattern = /^[12][90][0-9][0-9]-[01]?[0-9]-[0-3]?[0-9]$/;
   if(datefield.match(pattern))
   {
      var date_array = datefield.split('-');
      var year = date_array[0];

      // Attention! Javascript consider months in the range 0 - 11
      var month = date_array[1] - 1;
    
      var day = date_array[2];

      // This instruction will create a date object
      source_date = new Date(year,month,day);

      if(year != source_date.getFullYear())
      {
         alert('Year is not valid!');
         return false;
      }

      if(month != source_date.getMonth())
      {
         alert('Month is not valid!');
         return false;
      }

      if(day != source_date.getDate())
      {
         alert('Day is not valid!');
         return false;
      }
   }
   else
   {
      alert('Date format is not valid!');
      return false;
   }

   return true;
}

function checkLink()
{
	var r=confirm("Are you sure!");
	if (r==true)
	  {	  
	  return true;	  
	  }
	else
	  {	  
	  return false;
	  }
}

function checkFormInsertInterview()
{
   if(document.formInsertInterview.txtCVUsername.value=="")
        {
            alert("Please input CV Username");
            document.formInsertInterview.txtCVUsername.focus();
            return false;
        }
    if(document.formInsertInterview.txtNumberRound.value=="")
        {
           alert("Please input Number Round");
           document.formInsertStaff.txtNumberRound.focus();
           return false;
        }
    if(document.formInsertInterview.txtCVStatus.value=="")
        {
           alert("Please input CV Status");
           document.formInsertInterview.txtCVStatus.focus();
           return false;
        } 
}
function checkFormInsertFamily()
{
    if(document.formInsertFamily.txtRelative.value=="")
        {
            alert("Please input Staff of Relative");
            document.formInsertFamily.txtRelative.focus();
            return false;
        }
    if(document.formInsertFamily.txtFullName.value=="")
        {
           alert("Please input Full Name of Family");
           document.formInsertFamily.txtFullName.focus();
           return false;
        }
    if(document.formInsertFamily.txtGender.value=="")
        {
           alert("Please input Gender");
           document.formInsertFamily.txtGender.focus();
           return false;
        }
}
function checkFormEditStaff()
{
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    var stripped1 = document.formEditStaff.txtHomePhone.value.replace(/[\(\)\.\-\ ]/g, '');
    var stripped2 = document.formEditStaff.txtCellPhone.value.replace(/[\(\)\.\-\ ]/g, '');
    var stripped3 = document.formEditStaff.txtIDNumber.value.replace(/[\(\)\.\-\ ]/g, '');
    if(document.formEditStaff.txtStaffID.value=="")
        {
            alert("Please input Staff ID");
            document.formEditStaff.txtStaffID.focus();
            return false;
        }
    if(document.formEditStaff.txtFullName.value=="")
        {
           alert("Please input Full Name");
           document.formEditStaff.txtFullName.focus();
           return false;
        }
    if(document.formEditStaff.txtFirstName.value=="")
        {
           alert("Please input First Name");
           document.formEditStaff.txtFirstName.focus();
           return false;
        }
    if(document.formEditStaff.txtLastName.value=="")
        {
           alert("Please input Last Name");
           document.formEditStaff.txtLastName.focus();
           return false;
        }
    if(document.formEditStaff.txtPOB.value=="")
        {
           alert("Please input Place of Birthday");
           document.formEditStaff.txtPOB.focus();
           return false;
        }
    if(document.formEditStaff.txtMaristalStatus.value=="")
        {
           alert("Please input Marital Status");
           document.formEditStaff.txtMaristalStatus.focus();
           return false;
        }
    if(document.formEditStaff.txtPersonalTaxCode.value=="")
        {
           alert("Please input Personal Tax Code");
           document.formEditStaff.txtPersonalTaxCode.focus();
           return false;
        }
    if(document.formEditStaff.txtID_Number.value=="")
        {
           alert("Please input ID Number");
           document.formEditStaff.txtID_Number.focus();
           return false;
        }
    else
        {
            if(isNaN(parseInt(stripped3)))
                {
                    alert("The ID Number contains illegal characters");
                    document.formEditStaff.txtID_Number.focus();
                    return false;
                }
        }
    if(document.formEditStaff.txtPOI.value=="")
        {
           alert("Please input Place of Issue");
           document.formEditStaff.txtPOI.focus();
           return false;
        }
    if(document.formEditStaff.txtHomePhone.value=="")
        {
           alert("Please input Home Phone");
           document.formEditStaff.txtHomePhone.focus();
           return false;
        }
    /*else
        {
            if(isNaN(parseInt(stripped1)))
                {
                    alert("The phone number contains illegal characters");
                    document.formEditStaff.txtHomePhone.focus();
                    return false;
                }
            else if(stripped1.length>11||stripped1<9)
                {
                    alert("The phone number is the wrong length");
                    document.formEditStaff.txtHomePhone.focus();
                    return false;
                }
        }*/
     if(document.formEditStaff.txtCellPhone.value=="")
        {
           alert("Please input Cell Phone");
           document.formEditStaff.txtCellPhone.focus();
           return false;
        }
    /*else
        {
            if(isNaN(parseInt(stripped2)))
                {
                    alert("The phone number contains illegal characters");
                    document.formEditStaff.txtCellPhone.focus();
                    return false;
                }
            else if(stripped2.length>11||stripped2<9)
                {
                    alert("The phone number is the wrong length");
                    document.formEditStaff.txtCellPhone.focus();
                    return false;
                }
        }*/
   if(document.formEditStaff.txtPersonalEmail1.value=="")
        {
            alert("Please input Email");
            document.formEditStaff.txtPersonalEmail1.focus();
            return false;
        }
    else
        {
            if(!emailFilter.test(document.formEditStaff.txtPersonalEmail1.value))
                {
                    alert("Please enter a valid email address");
                    document.formEditStaff.txtPersonalEmail1.focus();
                    return false;
                }
            else if(document.formEditStaff.txtPersonalEmail1.value.match(illegalChars))
                {
                    alert("The email address contains illegal characters");
                    document.formEditStaff.txtPersonalEmail1.focus();
                    return false;
                }
        }
        if(document.formEditStaff.txtPersonalEmail2.value=="")
        {
            alert("Please input Email");
            document.formEditStaff.txtPersonalEmail2.focus();
            return false;
        }
    else
        {
            if(!emailFilter.test(document.formEditStaff.txtPersonalEmail2.value))
                {
                    alert("Please enter a valid email address");
                    document.formEditStaff.txtPersonalEmail2.focus();
                    return false;
                }
            else if(document.formEditStaff.txtPersonalEmail2.value.match(illegalChars))
                {
                    alert("The email address contains illegal characters");
                    document.formEditStaff.txtPersonalEmail2.focus();
                    return false;
                }
        }
    if(document.formEditStaff.txtCompanyEmail.value=="")
        {
            alert("Please input Email");
            document.formEditStaff.txtCompanyEmail.focus();
            return false;
        }
    else
        {
            if(!emailFilter.test(document.formEditStaff.txtCompanyEmail.value))
                {
                    alert("Please enter a valid email address");
                    document.formEditStaff.txtCompanyEmail.focus();
                    return false;
                }
            else if(document.formEditStaff.txtCompanyEmail.value.match(illegalChars))
                {
                    alert("The email address contains illegal characters");
                    document.formEditStaff.txtCompanyEmail.focus();
                    return false;
                }
        }
     if(document.formEditStaff.txtPSWD.value=="")
        {
            alert("Please input PA Number");
            document.formEditStaff.txtPSWD.focus();
            return false;
        }
       if(document.formEditStaff.txtPA_City.value=="")
        {
            alert("Please input PA City");
            document.formEditStaff.txtPA_City.focus();
            return false;
        }
         if(document.formEditStaff.txtPA_Country.value=="")
        {
            alert("Please input PA Country");
            document.formEditStaff.txtPA_Country.focus();
            return false;
        }
        if(document.formEditStaff.txtCVSumup.value=="")
        {
            alert("Please input CV Sumup");
            document.formEditStaff.txtCVSumup.focus();
            return false;
        }
       if(document.formEditStaff.txtCSWD.value=="")
        {
            alert("Please input CA Number");
            document.formEditStaff.txtCSWD.focus();
            return false;
        }
       if(document.formEditStaff.txtCA_City.value=="")
        {
            alert("Please input CA City");
            document.formEditStaff.txtCA_City.focus();
            return false;
        }
        if(document.formEditStaff.txtCA_Country.value=="")
        {
            alert("Please input CA Country");
            document.formEditStaff.txtCA_Country.focus();
            return false;
        }
       if(document.formEditStaff.txtVehicleNo.value=="")
        {
            alert("Please input Vehicle Number");
            document.formEditStaff.txtVehicleNo.focus();
            return false;
        }
       if(document.formEditStaff.txtVehicleType.value=="")
        {
            alert("Please input Vehicle Type");
            document.formEditStaff.txtVehicleType.focus();
            return false;
        }
        if(document.formEditStaff.txtVehicleColour.value=="")
        {
            alert("Please input Vehicle Color");
            document.formEditStaff.txtVehicleColour.focus();
            return false;
        }       
}
function checkEditInterview()
{
    if(document.formEditInterview.txtCVUserName.value=="")
        {
            alert("Please input CV UserName");
            document.formEditInterview.txtCVUserName.focus();
            return false;
        }
    if(document.formEditInterview.txtCVStatus.value=="")
        {
           alert("Please input CV Status");
           document.formEditInterview.txtCVStatus.focus();
           return false;
        }
}
function checkSearchByKey()
{
    if(document.searchByKey.keyword.value=="")
        {
            alert("Please input keyword");
            document.searchByKey.keyword.focus();
            return false;
        }
}
function checkExperience()
{
    if(document.formInsertExperience.txtPreviousPosition.value=="")
        {
            alert("Please input Previous Position");
            document.formInsertExperience.txtPreviousPosition.focus();
            return false;
        }
    if(document.formInsertExperience.txtCompany.value=="")
        {
            alert("Please input the Company");
            document.formInsertExperience.txtCompany.focus();
            return false;
        }
    if(document.formInsertExperience.txtIndustry.value=="")
        {
            alert("Please input the Industry");
            document.formInsertExperience.txtIndustry.focus();
            return false;
        }
    
}
function checkPassVi()
{
    if(document.formAddPassVi.txtType.value=="")
        {
            alert("Please input Type of Visa");
            document.formAddPassVi.txtType.focus();
            return false;
        }
    if(document.formAddPassVi.txtNationality.value=="")
        {
            alert("Please input the Nationality");
            document.formAddPassVi.txtNationality.focus();
            return false;
        }
    
}
function checkPassword()
{
    if(document.formChangePassWord.txtOldPass.value=="")
        {
            alert("Please input Old Password");
            document.formChangePassWord.txtOldPass.focus();
            return false;
        }
    if(document.formChangePassWord.txtNewPass.value=="")
        {
            alert("Please input new Password");
            document.formChangePassWord.txtNewPass.focus();
            return false;    
        }
    if(document.formChangePassWord.txtReNewPass.value=="") 
        {
            alert("Please input confirm new Passoword");
            document.formChangePassWord.txtReNewPass.focus();
            return false;
        }
    else
        {
            if(document.formChangePassWord.txtReNewPass.value!=document.formChangePassWord.txtNewPass.value)
                {
                    alert("Confirm new Password not correct");
                    document.formChangePassWord.txtReNewPass.focus();
                    return false;
                }
        }

}
function showUser(str)
{
            if (str=="2000")
            {
            document.getElementById("txtHint").innerHTML="";
            return;
            }
            if (window.XMLHttpRequest)
            {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
            }
            else
            {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange=function()
            {
                if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
                }
            }
        xmlhttp.open("GET","getuser?q="+str,true);
        xmlhttp.send();

}